#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main(int argc, char const *argv[]) {
  int pip[2];
  pipe(pip);
  pid_t pid;
  pid = fork();

  if (pid > 0) {
    close(pip[1]);
    waitpid(pid, NULL, 0);
    dup2(pip[0], STDIN_FILENO);
    execlp("wc", "wc", "-w", NULL);
    close(pip[0]);
  }

  if (pid == 0) {

    close(pip[0]);
    dup2(pip[1], STDOUT_FILENO);
    execlp("ls", "ls", NULL);
    close(pip[1]);
  }
  return 0;
}
